import draw.*;
import geometry.*;
import tester.*;
import java.util.*;
import colors.*;

class WholeGameWorld extends World{
  Mfmwg genie;
  ILoS stars;
  
  
  WholeGameWorld(Mfmwg genie, ILoS stars) {
    this.genie = genie;
    this.stars = stars;
  }
  /*
TEMPLATE:
   FIELDS:
    ... this.genie ...            --Mfmwg
    ... this.stars ...            --ILoS

    METHODS:
    ... this.onKeyEvent() ...      -- World
    ... this.onTick) ...           -- World
    ... this.draw() ...            -- boolean

    METHODS FOR FIELDS:
    ... this.stars.drawStars(Canvas c) ...  -- boolean
    ... this.stars.onTick(Mfmwg m) ...      -- ILoS
    ... this.stars.foundStar(Mfmwg m) ...   -- boolean
    ... this.stars.caughtStar(Mfmwg m) ...  -- boolean
    ... this.genie.drawMfmwg(Canvas c) ...  -- boolean
    ... this.genie.catchStar() ...          -- Mfmwg
    ... this.genie.onKeyEvent(String ke) ...-- Mfmwg
    ... this.genie.onTick() ...             -- Mfmwg
   */ 
  
  // produce a walker heading in the direction given by the key
  public World onKeyEvent(String ke){
    if (this.stars.foundStar(this.genie)){
      return new WholeGameWorld
      (this.genie.onKeyEvent(ke).catchStar(this.stars.caughtStar(this.genie)),
       this.stars);
    } else { return new WholeGameWorld(this.genie.onKeyEvent(ke), this.stars);}
  }
  
  //ticks the world once and updates all things.
  public World onTick(){
    if(this.genie.fuel <=0) { return endOfWorld("you're out of fuel, fool!");
    } else {
      return new WholeGameWorld(this.genie.onTick(),
                                this.stars.onTick(this.genie)); }
  }
  
  //draws the whole wide world.
  public boolean draw(){
    return this.genie.drawMfmwg(this.theCanvas) &&
    this.stars.drawStars(this.theCanvas);
    
  }
  
  public static void main(String[] argv){
    // construct an instance of a TimerWorld
    Examples w = new Examples();
    // and run the TimerWorld
    w.go();
  }
}